package Day13_StringBuilder类;

/*
    charAt方法:
            char charAt(int index)   s1.charAt(0)
            返回字符串中指定索引的字符, index表示索引
    字符串长度:
            s2.length() 是一个方法  数组长度是一个属性
 */

import java.util.Scanner;

public class String_遍历 {
    public static void main(String[] args) {
        //           012345
        String s1 = "a1b2c3";
        //charAt() 返回指定索引的char值
        System.out.println(s1.charAt(0)); //a
        System.out.println(s1.charAt(1)); //1
        System.out.println(s1.charAt(2)); //b
        System.out.println(s1.charAt(3)); //2

        //遍历字符串
        Scanner sc = new Scanner(System.in);
        System.out.println("输入字符串:");
        String s2 = sc.next();

        for (int i = 0; i < s2.length(); i++) {  //字符串长度 s2.length()    数组长度 arr.length
            System.out.print(s2.charAt(i) + " ");
        }
    }
}
